package com.myfum.mobile.tetris.data.cubes
{
	import com.myfum.mobile.tetris.Config;
	import com.myfum.mobile.tetris.interfaces.ISkinItem;
	
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;

	public class CubeData implements ISkinItem
	{
		public var type:int;
		public var x:int;
		public var y:int;
		
		private var _skin:BitmapData;
		
		public function CubeData(x:int, y:int, skin:BitmapData = null)
		{
			this.x = x;
			this.y = y;
			
			if(skin == null){
				this.skin = new BitmapData(Config.CUBE_SIZE, Config.CUBE_SIZE, false, 0xeecc33);
			}else{
				this.skin = skin;
			}
		}
		
		public function get skin():BitmapData{
			return _skin;
		}
		
		public function set skin(value:BitmapData):void{
			_skin = value;
		}
		
		public function get point():Point{
			return new Point(x, y);
		}
		
		public function clone():ISkinItem{
			var refer:Class = getDefinitionByName(getQualifiedClassName(this)) as Class;
			var c:CubeData = new refer(x, y, skin) as CubeData;
			return c;
		}
		
		public function dispose():void{
			skin.dispose();
		}
	}
}